using 组合模式;

/// <summary>
/// 表示文件系统中的文件夹  (容器节点Composite)
/// </summary>
public class Folder : FileSystemComponent
{
  private readonly List<FileSystemComponent> _children = new();

  public Folder(string name)
  {
    Name = name;
  }

  public void Add(FileSystemComponent component)
  {
    _children.Add(component);
  }

  public void Remove(FileSystemComponent component)
  {
    _children.Remove(component);
  }

  public override long GetSize()
  {
    return _children.Sum(child => child.GetSize()); // 递归求和
  }

  public override void Delete()
  {
    Console.WriteLine($"删除文件夹: {Name}");
    foreach (var child in _children)
    {
      child.Delete(); // 递归删除
    }
  }
}